﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="no"/>
  <xsl:param name="productTitle">Demo WebSite</xsl:param>
  <xsl:param name="productUrl"/>
  <xsl:param name="unsubscribeUrl">http://www.demo.com</xsl:param>

  <xsl:template match="/EventsToProcess">
    <MailGroup>
      <Mail>
        <xsl:attribute name="Subject">Recent activity on <xsl:value-of select="$productUrl"/>.</xsl:attribute>
        <MailView ContentType="text/plain">
          <Body xml:space="preserve">Dear <xsl:value-of select="Subscription/@User"/>,

This message was sent to you automatically by <xsl:value-of select="$productTitle"/> Server.

<xsl:apply-templates select="Event" mode="text"/>
This email was sent to: <xsl:value-of select="Subscription/@UserAddress"/>.
If you do not wish to receive notification messages from <xsl:value-of select="$productTitle"/>, please visit url : <xsl:value-of select="$unsubscribeUrl"/>.
          </Body>
        </MailView>
        <MailView ContentType="text/html">
          <Body>
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
              <head>
                <title>Recent activity on <xsl:value-of select="$productUrl"/></title>
              </head>
              <body>
                <p>
                  Dear <xsl:value-of select="Subscription/@User"/>,
                </p>
                <br/>
                <p>
                  This message was sent to you automatically by <xsl:value-of select="$productTitle"/> Server.
                </p>
                <br/>
                <table style="border-collapse: collapse; border-spacing: 10px;">
                  <tbody>
                    <tr>
                      <td style="width:30%; padding: 10px"><b>Event Details:</b></td>
                      <td style="padding: 10px"><b>Event Message</b></td>
                    </tr>
                    <xsl:apply-templates select="Event" mode="html"/>
                  </tbody>
                </table>
                <br/>
                <p>
                  This email was sent to: <xsl:value-of select="Subscription/@UserAddress"/>
                </p>
                <p>
                  If you do not wish to receive notification messages from <xsl:value-of select="$productTitle"/>, please click <a><xsl:attribute name="href"><xsl:value-of select="$unsubscribeUrl"/></xsl:attribute>here</a>.
                </p>
              </body>
            </html>
          </Body>
        </MailView>
      </Mail>
    </MailGroup>
  </xsl:template>

  <xsl:template match="Event" mode="text" xml:space="preserve">Event: <xsl:value-of select="@EventType"/> (<xsl:value-of select="@Time"/>)

<xsl:value-of select="@Message"/>
<xsl:if test="@RelatedPageURL">See more details: <xsl:value-of select="@RelatedPageURL"/></xsl:if>
</xsl:template>
    
  <xsl:template match="Event" mode="html">
    <tr>
      <!--event details-->
      <td style="vertical-align: top; padding: 10px; color:gray">
        <div>
          Time: <xsl:value-of select="@Time"/><br/>
          Type: <xsl:value-of select="@EventType"/><br/>
          Category: <xsl:value-of select="@Category"/><br/>
          Component: <xsl:value-of select="@Component"/><br/>
          Author: <a>
            <xsl:attribute name="href">
              mailto:<xsl:value-of select="@UserAddress"/>
            </xsl:attribute>
            <xsl:value-of select="@User"/>
          </a>
        </div>
      </td>
      <!--event message-->
      <td style="vertical-align: top; padding: 10px">
        <div>
          <xsl:value-of select="@Message"/>
        </div>
        <xsl:if test="@RelatedPageURL">
          <div>
            <p>
              See also <a>
                <xsl:attribute name="href">
                  <xsl:value-of select="@RelatedPageURL"/>
                </xsl:attribute>
                <xsl:value-of select="@RelatedPageURL"/>
              </a>
            </p>
          </div>
        </xsl:if>
      </td>
    </tr>
  </xsl:template>
</xsl:stylesheet>
